package com.BookManager.mapper;

import com.BookManager.entity.Book;
import com.BookManager.entity.Lend;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface BookMapper {

    //查询借阅信息
    @Results({
            @Result(column = "l_id",property = "lid"),
            @Result(column = "s_id",property = "sid"),
            @Result(column = "b_id",property = "bid"),
            @Result(column = "l_time",property = "time"),
            @Result(column = "s_name",property = "sName"),
            @Result(column = "b_title",property = "bName")
    })
    @Select("SELECT * from lend " +
            "left join student on lend.s_id = student.s_id " +
            "left join book on book.b_id = lend.b_id")
    List<Lend> getLendList();

    //添加借阅信息
    @Insert("insert into lend(s_id,b_id,l_time) values (#{sid},#{bid},NOW())")
    void addLend(@Param("sid") int sid,@Param("bid") int bid);

    //删除借阅信息
    @Delete("delete from lend where l_id = #{lid}")
    void deleteLend(int lid);

    //查询书本
    @Results({
            @Result(column = "b_id",property = "bid"),
            @Result(column = "b_title",property = "title"),
            @Result(column = "b_info",property = "info"),
            @Result(column = "b_price",property = "price")
    })
    @Select("select * from book")
    List<Book> getBookList();


    //添加书本
    @Insert("insert into book(b_title,b_info,b_price) values(#{title},#{info},#{price})")
    void addBook(@Param("title") String title,@Param("info") String info,@Param("price") double price);

    //删除书本
    @Delete("delete from book where b_id = #{bid}")
    void deleteBook(int bid);

}
